<?php
namespace Api\Controller;
use Think\Controller;
class TrainController extends Controller {

    /*俱乐部列表  开发人：周弈男*/
    public function alltrain(){
       $grade=$_GET['grade']; 
       $train=M('train');
       if($grade=="3"){
          $train=$train->select();
       }else{
          $train=$train->where("grade=$grade")->select();
       }
       if($train==null){
        $this->ajaxReturn($train);
       }else{
        $this->ajaxReturn($train);
       }   
    }

    public function gettrain(){
      $trainid=$_GET['trainid'];
      $train=M('train');
      $train=$train->where("trainid=$trainid")->find();
      if($train==null){
        $this->ajaxReturn($train);
      }else{
        $this->ajaxReturn($train);
      }
    }

    public function follow(){
      $follow=M('follow');
      $trainid=$_GET['trainid'];
      $uid=$_GET['uid'];
      $type=$_GET['type'];

      $data['userid']=trim($uid);
      $data['type']=trim($type);
      $data['id']=trim($trainid);
      $exist=$follow->where($data)->find();
      if($exist!==null){
        $re['success']='0';
        $follow=$follow->where($data)->delete();
        $this->ajaxReturn($re);
      }else{
        $re['success']='1';
        $follow=$follow->add($data);
        $this->ajaxReturn($re);
      }
    }

    public function isCollected(){
      $follow=M('follow');
      $trainid=$_GET['trainid'];
      $uid=$_GET['uid'];
      $type=$_GET['type'];

      $data['userid']=trim($uid);
      $data['type']=trim($type);
      $data['id']=trim($trainid);
      $exist=$follow->where($data)->find();
      if($exist!==null){
        $re['collected']='1';
        $this->ajaxReturn($re);
      }else{
        $re['collected']='0';
        $this->ajaxReturn($re);
      }
    }

    public function lunbo(){
       $train=M('train');
       $train=$train->field('trainid,pic')->select();
       if($train==null){
          $this->ajaxReturn($train);
       }else{
          $this->ajaxReturn($train);
       }
    }
  }
